import { createRouter, createWebHistory } from "vue-router";
const routes = [
  {
    path: "/home",
    component: () => import("../views/home/Home.vue"),
  },
  {
    path: "/center",
    component: () => import("../views/center/Center.vue"),
  },
  {
    path: "/cart",
    component: () => import("../views/cart/Cart.vue"),
    meta: {
      isAuth: true,
    },
  },
  {
    path: "/order",
    component: () => import("../views/order/Order.vue"),
    meta: {
      isAuth: true,
    },
  },
  {
    path: "/",
    redirect: "/home",
  },
  {
    path: "/store",
    component: () => import("../views/Store/Sotre.vue"),
  },
  {
    path: "/createorder",
    component: () => import("../views/createOrder/CreateOrder.vue"),
    meta: {
      isAuth: true,
    },
  },
  {
    path: "/address",
    component: () => import("../views/address/Address.vue"),
    meta: {
      isAuth: true,
    },
  },
  {
    path: "/addressEdit",
    component: () => import("../views/addressEdit/AddressEdit.vue"),
    meta: {
      isAuth: true,
    },
  },
  {
    path: "/userinfoedit",
    component: () => import("../views/userinfoEdit/UserInfoEdit.vue"),
    meta: {
      isAuth: true,
    },
  },
  {
    path: "/login",
    component: () => import("../views/login/Login.vue"),
  },
  {
    path: "/register",
    component: () => import("../views/register/Register.vue"),
  },
];
const router = createRouter({
  history: createWebHistory(),
  routes,
});
router.beforeEach((to, from, next) => {
  if (to.meta.isAuth) {
    if (localStorage.isLogin === "login") {
      next();
    } else {
      showToast("请先登录");
      next("/login");
    }
  } else {
    next();
  }
});
export default router;
